package com.crm.eg.service.impl;

import java.util.List;

import com.crm.eg.bean.UserAccount;
import com.crm.eg.dao.UserAccountDAO;
import com.crm.eg.service.UserAccountService;
import com.crm.exception.DBException;

public class UserAccountServiceImpl implements UserAccountService {

	private UserAccountDAO userAccountDAO; // inject userAccountDAO

	public UserAccountDAO getUserAccountDAO() {
		return userAccountDAO;
	}

	public void setUserAccountDAO(UserAccountDAO userAccountDAO) {
		this.userAccountDAO = userAccountDAO;
	}

	public void saveUserAccount(UserAccount userAccount) throws DBException {

		try {
			userAccountDAO.save(userAccount);
		} catch (DBException re) {
			throw new DBException(re);
		}
	}

	public void deleteUserAccount(Long id) throws DBException {
		UserAccount userAccount = new UserAccount();
		userAccount.setUserid(id);
		try {
			userAccountDAO.delete(userAccount);
		} catch (DBException re) {
			throw new DBException(re);
		}

	}

	public List<UserAccount> getAllUserAccount() throws DBException {
		try {
			return userAccountDAO.findAll();
		} catch (DBException re) {
			throw new DBException(re);
		}

	}

	public UserAccount getUserAccountById(Long id) throws DBException {
		try {
			return userAccountDAO.findById(id);
		} catch (DBException re) {
			throw new DBException(re);
		}

	}

	public List<UserAccount> getUserAccountByUserName(String username)
			throws DBException {
		try {
			return userAccountDAO.findByUsername(username);
		} catch (DBException re) {
			throw new DBException(re);
		}

	}

}
